﻿using UnityEngine;

public class TKChessComponent : BaseComponent
{
    private SpriteRenderer spriteRenderer;
    public override void Binding()
    {
        TKChessComponentModel cm = (TKChessComponentModel)GetComponentModel();
        spriteRenderer = GetComponent<SpriteRenderer>();
        BindData(cm.posDM, (Vector3 value) =>
        {
            transform.localPosition = value;
        });
        BindData(cm.imageDM, ((string, string) value) =>
        {
            AddressablesUtility.LoadSpriteFromAtlasAsync(value.Item1, value.Item2, (Sprite sprite) =>
            {
                if (gameObject != null && !gameObject.Equals(null))
                {
                    spriteRenderer.sprite = sprite;
                }
            });
        });
        BindData(cm.isSelectedDM, (bool value) =>
        {
            spriteRenderer.color = value ? new Color(1, 1, 1, 0.7f) : new Color(1, 1, 1, 1);
        });
    }

    public override void UnBinding()
    {

    }
}
